# Contributor: Melven Roehrig-Zoellner <Melven.Roehrig-Zoellner@DLR.de>

_realname=tixi
pkgbase=mingw-w64-${_realname}3
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}3"
pkgver=3.3.0
pkgrel=2
pkgdesc="TiXI is a fast and simple XML interface library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/DLR-SC/tixi'
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-fc"
             "${MINGW_PACKAGE_PREFIX}-python")
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt")
source=("https://github.com/DLR-SC/tixi/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        0002-Dont-build-and-install-the-examples.patch)
sha256sums=('988d79ccd53c815d382cff0c244c0bb8e393986377dfb45385792766adf6f6a9'
            '632b435c9793f14c1f21509e8f9724eb0c3b17f5970b18f7c005c02b5160e502')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0002-Dont-build-and-install-the-examples.patch"
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DTIXI_ENABLE_FORTRAN=On \
      -DBUILD_SHARED_LIBS=On \
      "${extra_config[@]}" \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}3/LICENSE"
}
